package com.ljtg.ljtgservice.controller.admin;

import com.ljtg.ljtgpojo.dto.CIdAndDay;
import com.ljtg.ljtgpojo.dto.CategoryDTO;
import com.ljtg.ljtgpojo.dto.CategoryPageQueryDTO;
import com.ljtg.ljtgpojo.entity.Category;
import com.ljtg.ljtgservice.service.CategoryService;
import com.ljtg.result.PageResult;
import com.ljtg.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/category")
@Tag(name = "分类管理接口", description = "分类管理接口")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    //新增分类
    @PostMapping
    @Operation(summary = "新增分类", description = "添加一个新的分类")
    public Result<String> addCategory(@RequestBody CategoryDTO categoryDTO) {
        categoryService.addCategory(categoryDTO);
        return Result.success();
    }

    //修改分类
    @PutMapping
    @Operation(summary = "修改分类", description = "更新分类信息")
    public Result<String> updateCategory(@RequestBody CategoryDTO categoryDTO) {
        categoryService.updateCategory(categoryDTO);
        return Result.success();
    }

    //根据id删除分类
    @DeleteMapping("/{id}")
    @Operation(summary = "删除分类", description = "根据ID删除分类")
    public Result<String> deleteCategory(@PathVariable Long id) {
        categoryService.deleteCategory(id);
        return Result.success();
    }

    //分页查询
    @GetMapping("/page")
    @Operation(summary = "分页查询分类", description = "根据条件分页查询分类")
    public Result<PageResult> page(CategoryPageQueryDTO categoryPageQueryDTO) {
        PageResult pageResult = categoryService.pageQuery(categoryPageQueryDTO);
        return Result.success(pageResult);
    }

    //启用/禁用分类
    @PostMapping("/status/{status}")
    @Operation(summary = "启用/禁用分类", description = "启用或禁用分类")
    public Result<String> startOrStop(@PathVariable Integer status, Long id) {
        categoryService.startOrStop(status, id);
        return Result.success();
    }

    //查询分类
     @Operation(summary = "查询分类", description = "查询分类")
     @GetMapping("/list")
    public Result<List<Category>> list() {
        List<Category> list = categoryService.list();
        return Result.success(list);
    }



}